<template>
  <div class="order">
    <!-- 地址 -->
  <address-info-vue ref="address"></address-info-vue>

  <!-- 商品 -->
  <shop-info-vue></shop-info-vue>

  <van-submit-bar :price="allPrice*100" button-text="确认订单" @submit="onSubmit" />
    </div>
</template>

<script>
import addressInfoVue from "./components/addressInfo.vue"
import shopInfoVue from "./components/shopInfo.vue"
import {reqOrderAdd} from "../../http/api";
import {Toast} from "vant"
export default {
  components: {
    addressInfoVue,
    shopInfoVue,
  },
  data() {
    return {
      allPrice:JSON.parse(sessionStorage.getItem("orderInfo")).countmoney
    }
  },
  methods: {
    onSubmit(){
      if(this.$refs.address.info.id){
        reqOrderAdd({
          uid:JSON.parse(localStorage.getItem("isLogin")).uid,
          addressId:this.$refs.address.info.id,...JSON.parse(sessionStorage.getItem("orderInfo"))
        }).then((res)=>{
          if(res.data.code==200){
            this.$router.replace("/pay?orderId="+res.data.list.outTradeNo)
          }
        })
      }else{
        Toast("亲选择收货地址")
      }
    }
  }
}
</script>

<style scoped lang="less">
@import url(../../less/index.less);
.van-button__text{
  font-size: 0.3rem;
  color: #fff;
}
</style>